[HDX-5080] Chart editor UI for metric formulas - #2909
Conversation
🦋 Changeset detectedLatest commit: 43cd185 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR exposes metric formulas in the chart editor and coordinates their persistence, rendering metadata, and alert evaluation.
Confidence Score: 4/5The PR is not yet safe to merge because series edits can still silently change which operands existing formulas evaluate. Moving, duplicating, or removing a series mutates its positional index without rewriting formula expressions, while validation checks only whether letter references remain within the current series count; an expression can therefore stay valid but compute against different metrics. Files Needing Attention: packages/app/src/components/DBEditTimeChartForm/ChartSeriesEditor.tsx, packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx
|
| Filename | Overview |
|---|---|
| packages/app/src/components/DBEditTimeChartForm/ChartFormulaEditor.tsx | Adds formula expression, alias, formatting, removal, and live validation controls. |
| packages/app/src/components/DBEditTimeChartForm/ChartSeriesEditor.tsx | Adds positional reference badges, but existing series mutations still leave formula expressions unchanged. |
| packages/app/src/components/ChartEditor/utils.ts | Adds formula-aware normalization and validation for supported metric chart types. |
| packages/app/src/source.ts | Maps number formats and value-column counts across operand, formula, and ratio query layouts. |
| packages/app/src/components/DBTableChart.tsx | Uses formula-aware value-column counts for group-by inference and column coloring. |
| packages/app/src/components/DBTimeChart.tsx | Avoids invalid value-range drill-down filtering when formula operands are hidden. |
| packages/api/src/tasks/checkAlerts/index.ts | Preserves formulas and ratio mode in tile alerts while forcing formula-only alert query results. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Editor[Chart editor series and formulas] --> Validate[Formula validation]
Validate --> Config[Saved metric chart config]
Config --> Query[Composed metric query]
Query --> Operands[Operand columns]
Query --> Formulas[Formula columns]
Operands --> Charts[Chart consumers]
Formulas --> Charts
Config --> AlertConfig[Alert config rebuild]
AlertConfig --> FormulaOnly[Formula-only alert query]
FormulaOnly --> Threshold[Threshold evaluation]
Reviews (6): Last reviewed commit: "fix: evaluate metric formulas in tile al..." | Re-trigger Greptile
Deep ReviewScope: PR #2909 — Chart editor UI for metric formulas (HDX-5080), base The alert value-column mechanics were verified directly against source: 🟡 P2 -- recommended
🔵 P3 nitpicks (2)
Reviewers (2 returned + orchestrator verification): ce-agent-native-reviewer, ce-learnings-researcher, plus direct orchestrator code verification of the alert-evaluation and renderer-projection paths. Nine dispatched persona reviewers (correctness, adversarial, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, api-contract, reliability) had not returned when output was finalized; findings above reflect only confirmed, diff-grounded issues and should not be read as a clean bill from those lenses. Testing gaps:
|
8d9e37e to
41b2354
Compare
2067484 to
226e1a9
Compare
226e1a9 to
1010ee4
Compare
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (11 lines, under the 30-line bar for Tier 4) Review process: Full human review — logic, architecture, edge cases. Stats
|
E2E Test Results✅ All tests passed • 302 passed • 1 skipped • 975s
Tests ran across 4 shards in parallel. |
1010ee4 to
862a3cf
Compare
Expose metric formulas (HDX-5078 schema, HDX-5079 rendering) in the chart editor for metric sources: - Formula rows in the builder (Add Formula / Remove Formula) with a letter-ref expression input, alias, and per-formula number format - Inline validation via the structured validator (malformed expressions, unknown series refs) plus save-time validation in validateChartForm - Letter badges (A, B, C) on metric series rows so refs are discoverable - Show input series toggle (showOperandSeries) for formula-only output; Number tiles default to hidden operands since they render the first value column - Formulas and the As Ratio toggle are mutually exclusive in the editor - normalizeChartConfig strips formulas for non-metric sources and display types the composed metric query does not render - useChartNumberFormats / DBTableChart / DBTimeChart updated for the formula-aware value-column projection (operands first unless hidden, then formula columns)
getChartConfigFromAlert rebuilds a builder tile's chart config from an explicit field list and dropped formulas/showOperandSeries, so an alert on a formula tile queried only the raw operand series and compared the threshold against the last operand's value (e.g. raw bytes) instead of the formula result — regardless of the tile's "Show input series" toggle. - Pass formulas through and always drop operand columns from the alert query (showOperandSeries: false) so the formula is the value column parseAlertData picks - Also pass ratioMode through: grouped share_of_total ratio tile alerts previously evaluated as per_group (the default) - Integration tests: formula value drives the alert (value distinct from both operands), toggle-independence, NULL formula (zero denominator) skipped, and share_of_total ratioMode honored
6c9d2db to
43cd185
Compare


Summary
Exposes metric formulas (HDX-5078's
formulasconfig, rendered by HDX-5079) in the chart editor for metric sources, so a derived series likeA / (A + B + C) * 100can be built, validated, saved, and reloaded from the UI.Rebased onto main now that #2908 (HDX-5079 rendering) has merged.
Editor
ChartFormulaEditor) on metric-source builder charts (time series / table / number): "Add Formula" appends a row with a monospace letter-ref expression input, an alias, a per-formula number format (reuses the per-series format drawer), and "Remove Formula".validateFormula): malformed expressions, unknown series refs, constant-only expressions, etc. surface live under the input;validateChartFormblocks save/run with the same messages so an invalid expression can never reach ClickHouse.A,B,C, ...) on metric series rows so formula refs are discoverable.showOperandSeries(formula + raw operand series vs formula column(s) only). Adding a formula on a Number tile defaults operands to hidden, since Number tiles render the first value column.A / (A + B + C)can be built.normalizeChartConfigstripsformulas/showOperandSerieson save for non-metric sources and for display types the composed metric query does not render (pie/bar/heatmap/search/patterns), mirroring the existingmetricName/havingstripping. The form state keeps them, so switching back restores the rows.Rendering consumers (positional value-column contract)
The composed metric query projects operand columns (unless hidden) then formula columns, ahead of group-by passthrough columns. Updated the consumers that map columns positionally:
useChartNumberFormats: operand columns →select[i].numberFormat, formula columns →formulas[j].numberFormat, both falling back to the chart-wide format; chart-wide axis format prefers formula formats when operands are hidden.getBuilderValueColumnCounthelper (formula/ratio-aware) used byDBTableChartfor group-by column inference; per-column color mapping skips hidden-operand formula configs.DBTimeChartdrill-down skips the value-range filter when operands are hidden (formula columns don't map ontoselectexpressions).alias || expression).Persistence needs no API changes: tiles validate against
SavedChartConfigSchema, which already carriesformulas/showOperandSeries, andbuilderToRawSqlalready rejects formula configs with a clear message on the Builder → SQL switch.Alerts on formula tiles (
packages/api)Contrary to #2908's "alerts work with no changes" claim, the alert task does not run the tile config as-is —
getChartConfigFromAlertrebuilds it from an explicit field list that droppedformulas/showOperandSeries. An alert on a formula tile therefore queried only the raw operand series and compared the threshold against the last operand's value (e.g.740442112.0 meets or exceeds 0.1for a byte-valued operand), regardless of the tile's "Show input series" toggle. Fixed here:formulasis passed through, and operand columns are always dropped from the alert query (showOperandSeries: false) so the formula is the value columnparseAlertDatapicks — the alert evaluates exactly what the tile displays.ratioModeis now passed through, so groupedshare_of_totalratio tile alerts no longer silently evaluate asper_group.make dev-int FILE=checkAlerts, 168 passing): formula value drives the alert (fixture chosen so the formula result differs from both operands), toggle-independence, NULL formula (zero denominator) skipped without NaN history, andshare_of_totalhonored (asserting the exact share value aper_groupfallback couldn't produce).Testing
make ci-lint,make ci-unitpass.DBEditTimeChartForm.test.tsx: Add/Remove Formula, inline validation (malformed / unknown ref / clears when fixed), save round-trip, save blocked on invalid expression, ratio mutual exclusion,showOperandSeriestoggle, non-metric sources show no formula controls.ChartEditor/utils.test.ts:validateChartFormformula rules (including the Number-tile cap lift) and normalization stripping/round-trip.source.test.ts:useChartNumberFormatsformula-column mapping (operands shown/hidden, ratio precedence, chart-format fallbacks) andgetBuilderValueColumnCount.make dev-e2e FILE=dashboard GREP="Metric formulas", passing): creates a metric table tile with two gauge series +A / (A + B) * 100, asserts the inline error for an invalid ref, hides operands, saves, reloads the page, verifies the formula column renders with a finite value, and reopens the editor to verify the round-trip.How to test on Vercel preview
A/Bbadges), click Add Formula, enterA / (A + B) * 100.A / Cto see the inline error; toggle Show input series; save, reload, and confirm the tile renders the formula series.References
Screenshots